import {likeDetail} from '@/api'
const state = {
    // 详情页面的商品信息
    shopInfo: {},
    // 商品信息
    pre: {
        shopId0: '',
        dealgroupPrice0: '',
        marketPrice0: ''
    }
}

const actions = {
    // 获取该页的商品信息
    async getShopInfo({ commit }, shopId) {
        // 由于数据库数据较少
        // shopId = shopId < 2 ? shopId : 2;
        // 商品的第一部分信息
        const result = await likeDetail(shopId);
        if (result.code === 200) {
            // 获取成功
            commit('GETSHOPINFO',result.likeDetail[0])         
        }
    },
    // 保存商品信息
    savePre({ commit }, { shopId0, dealgroupPrice0, marketPrice0 }) {
        let pre = {shopId0,dealgroupPrice0,marketPrice0}
        commit('SAVEPRE',pre)
    }
}

const mutations = {
    // 第一部分商品信息
    GETSHOPINFO(state,shopInfo) {
        state.shopInfo = shopInfo
    },
    // 保存商品信息
    SAVEPRE(state, pre) {
        state.pre = pre
    }
}

const getters = {
    imgs(state) {
        return state.shopInfo.imgs || []
    },
    foodList(state) {
        return state.shopInfo.foodList || []
    },
    otherShops(state) {
        return state.shopInfo.otherShops || []
    }
}

export default {
    actions,
    mutations,
    state,
    getters
}